package com.cdxy.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @Author: tangy
 * @Date: 2020/3/7 18:31
 */
@Component
public class PropertiesUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;
    private static Environment environment;

    public PropertiesUtil() {
    }

    public static String getProperty(String key) {
        return environment.getProperty(key);
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        PropertiesUtil.applicationContext = applicationContext;
        environment = applicationContext.getEnvironment();
    }

    public static Environment getEnvironment() {
        return environment;
    }
}